package multithread;

public class ThreadDemo4 {
    public static void main(String[] args) {
        Object A =new Object();
        Object B =new Object();

        Thread t1 = new Thread(()->{
            synchronized (A){
                try {
                    //给t2足够时间拿到B
                    Thread.sleep(1000);
                } catch (InterruptedException e){
                    e.printStackTrace();
                }
                //尝试获取B，并没有释放A
                synchronized (B){
                    System.out.println("t1拿到了两把锁");
                }
            }
        });
        Thread t2 = new Thread(()->{
            synchronized (B){
                try {
                    //给t1足够时间拿到A
                    Thread.sleep(1000);
                } catch (InterruptedException e){
                    e.printStackTrace();
                }
                synchronized (A){
                    System.out.println("t2拿到了两把锁");
                }
            }
        });
        t1.start();
        t2.start();



    }
}
